package com.tanhua.manage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanhua.manage.domain.AnalysisByDay;
import com.tanhua.manage.domain.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {
    /**
     * 查询新注册用户
     */
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log " +
            "WHERE TYPE=#{type} AND log_time=#{today}")
    Long queryNumsByType(@Param("type") String type, @Param("today") String today);

    /**
     * 查询活跃用户
     */
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time=#{today}")
    Long queryNumsByTime(@Param("today") String today);

    /**
     * 查询次日留存用户数
     */
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log \n" +
            "WHERE TYPE='0101' AND log_time=#{today} AND user_id IN (\n" +
            "SELECT user_id FROM tb_log WHERE TYPE='0102' AND log_time=#{yesterday})")
    Long queryNumRetention1d(@Param("today") String today, @Param("yesterday") String yesterday);
}
